# coding: UTF-8
# ----------
# Project_Name : pythonProject
# File_Name : huangcongbing
# Author : asus
# Date_Time:2022/4/24 18:53
# Description :
# ----------
# 按照标准unittest编写一条百度地图的导航测试用例
import unittest  # 导入测试框架

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions

class Ljtest(unittest.TestCase):  # 必须继承TesCase类
    # 测试前
    def setUp(self) -> None:
        self.driver = webdriver.Chrome()
        self.wait = WebDriverWait(self.driver, 30)
        self.driver.maximize_window()
        self.driver.get('https://map.baidu.com/')
        self.driver.find_element(By.XPATH,'//*[@id="TANGRAM__PSP_36__closeBtn"]').click()

    # 测试中
    def test(self):
        self.wait.until(expected_conditions.visibility_of_element_located((By.ID,'sole-input')))#加入显示等待
        self.driver.find_element(By.ID,'sole-input').send_keys('大熊猫繁育基地')
        time.sleep(3)
        #self.wait.until(expected_conditions.visibility_of_element_located((By.ID,'search-button')))  # 加入显示等待
        self.driver.find_element(By.XPATH,'//*[@id="sole-searchbox-content"]/div[2]').click()#点击搜索
        time.sleep(2)
        self.driver.find_element(By.XPATH,'//*[@id="route-searchbox-content"]/div[1]/div[1]/div[2]').click()#点击驾车出行方式
        self.driver.find_element(By.XPATH,'//*[@id="route-searchbox-content"]/div[2]/div/div[2]/div[1]/input').send_keys('火车北站')#输出起始出发点
        self.driver.find_element(By.XPATH,'//*[@id="route-searchbox-content"]/div[2]/div/div[2]/div[1]/input').send_keys(Keys.ENTER)#回车确定
        time.sleep(5)
        self.driver.find_element(By.XPATH,'//*[@id="route_top"]/ul/li[1]').click()#推荐路线
        self.driver.find_element(By.XPATH,'//*[@id="navtrans_content"]/div[1]/div[1]').click()#第一个推荐路线
        # ActionChains(self.driver).context_click().perform()
        time.sleep(3)


    #测试后
    def tearDown(self) -> None:
        time.sleep(2)
        self.driver.quit()
